package com.vasthu.core.service;

import com.vasthu.api.dao.ItemDAO;
import com.vasthu.api.domain.Item;
import com.vasthu.api.service.ItemManagerService;
import com.vasthu.core.dao.ItemDAOImpl;
import com.vasthu.gui.VstTableItemSelectable;
import com.vasthu.utility.VstDBManager;
import java.util.*;
import java.sql.*;

public class ItemManagerServiceImpl implements ItemManagerService {

    private ItemDAO itemDao;

    public ItemManagerServiceImpl() {
        itemDao = new ItemDAOImpl();
    }

    public boolean insertItem(Item item) {
        if (item == null) {
            return false;
        }
        boolean ok = itemDao.insertItem(item);
        return ok;
    }

    public Item getItemById(long itemId) {
        Item item = itemDao.getItemById(itemId);
        return item;
    }

    public Item getItemByCode(String itemCode) {
        Item item = itemDao.getItemByCode(itemCode);
        return item;
    }

    public boolean deleteItemById(long itemId) {
        boolean ok = itemDao.deleteItemById(itemId);
        return ok;
    }

    public List<String> getAllItemCodes() {
        List<Item> itemList = new ArrayList<Item>();
        List<String> itemNameList = new ArrayList<String>();
        itemList = itemDao.getAllItems();
        for (Item item : itemList) {
            itemNameList.add(item.getItemCode());
        }
        return itemNameList;
    }

    public List<VstTableItemSelectable> getAllItemsForTable() {
        List<Item> itemList = new ArrayList<Item>();
        List<VstTableItemSelectable> dataList = new ArrayList<VstTableItemSelectable>();
        itemList = itemDao.getAllItems();
        for (Item item : itemList) {
            dataList.add(item);
        }
        return dataList;
    }
}